clear all

***"0. Directories and append datasets" 
cd "C:\Users\Galasso\Dropbox\research\papers\COVID_Vaccine\vaccine"
clear 

use "C:\Users\Galasso\Dropbox\research\papers\COVID_Vaccine\vaccine\vaccine_GER2022.dta"

append using "C:\Users\Galasso\Dropbox\research\papers\COVID_Vaccine\vaccine\vaccine_AUS2022.dta"
append using "C:\Users\Galasso\Dropbox\research\papers\COVID_Vaccine\vaccine\vaccine_AUT2022.dta"
append using "C:\Users\Galasso\Dropbox\research\papers\COVID_Vaccine\vaccine\vaccine_FR2022.dta"
append using "C:\Users\Galasso\Dropbox\research\papers\COVID_Vaccine\vaccine\vaccine_IT2022.dta"
append using "C:\Users\Galasso\Dropbox\research\papers\COVID_Vaccine\vaccine\vaccine_NZ2022.dta"
append using "C:\Users\Galasso\Dropbox\research\papers\COVID_Vaccine\vaccine\vaccine_UK2022.dta"
append using "C:\Users\Galasso\Dropbox\research\papers\COVID_Vaccine\vaccine\vaccine_SW2022.dta"
append using "C:\Users\Galasso\Dropbox\research\papers\COVID_Vaccine\vaccine\vaccine_US2022.dta"


*** I. Create or change control and outcome variables ***

gen highmort_country=1 if country_code==43|country_code==33|country_code==39|country_code==44|country_code==1|country_code==46
replace highmort_country=0 if country_code==49|country_code==61|country_code==64


** Create Country-region dummies, assigning a value to missing obs"
egen region_id = group(country region), missing

** Generate new variables
gen young_1 = (agegroup_1==1) if agegroup_1 != .
assert young_1 == . if agegroup_1 == . 
assert young_1 != . if agegroup_1 != .

gen youngadult_1 = (agegroup_1==2) if agegroup_1 != .
assert youngadult_1 == . if agegroup_1 == . 
assert youngadult_1 != . if agegroup_1 != .

gen adult_1 = (agegroup_1==2|agegroup_1==3) if agegroup_1 != .
assert adult_1 == . if agegroup_1 == . 
assert adult_1 != . if agegroup_1 != .

gen fifty_1 = (agegroup_1==3) if agegroup_1 != .
assert fifty_1 == . if agegroup_1 == . 
assert fifty_1 != . if agegroup_1 != .

gen old_1 = (agegroup_1==4) if agegroup_1 != .
assert old_1 == . if agegroup_1 == . 
assert old_1 != . if agegroup_1 != .

gen young_2 = (agegroup_2==1) if agegroup_2 != .
assert young_2 == . if agegroup_2 == . 
assert young_2 != . if agegroup_2 != .

gen adult_2 = (agegroup_2==2|agegroup_2==3) if agegroup_2 != .
assert adult_2 == . if agegroup_2 == . 
assert adult_2 != . if agegroup_2 != .

gen old_2 = (agegroup_2==4) if agegroup_2 != .
assert old_2 == . if agegroup_2 == . 
assert old_2 != . if agegroup_2 != .

gen fiftyplus_1=fifty_1+old_1

**tvc : I add a condition on missing values of the underlying variables defining info_media_1. Without this condition info_media_1 was different of "." while one of the underlying variables was equal to ".".
egen info_media_1= rowmean(info_tv_1 info_radio_1 info_newpaper_1) if info_tv_1 != . & info_radio_1 != . & info_newpaper_1 != . 
assert info_media_1 == . if info_tv_1 == . | info_radio_1 == . | info_newpaper_1 == . 
assert info_media_1 != . if info_tv_1 != . & info_radio_1 != . & info_newpaper_1 != . 

gen whitec_1 = (occupation_1==1) if occupation_1 != .
assert whitec_1 == . if occupation_1 == . 
assert whitec_1 != . if occupation_1 != .

gen servicew_1 = (occupation_1==2) if occupation_1 != .
assert servicew_1 == . if occupation_1 == . 
assert servicew_1 != . if occupation_1 != .

gen bluec_1 = (occupation_1==3) if occupation_1 != .
assert bluec_1 == . if occupation_1 == . 
assert bluec_1 != . if occupation_1 != .

gen inoperative_1 = (occupation_1==4) if occupation_1 != .
assert inoperative_1 == . if occupation_1 == . 
assert inoperative_1 != . if occupation_1 != .



gen covidother_1=covidfamily_1+covidfriends_1+covidhome_1
gen covidother_2=covidfamily_2+covidfriends_2+covidhome_2
gen covidotherD_1=1 if covidother_1==1|covidother_1==2|covidother_1==3
replace covidotherD_1=0 if covidother_1==0
gen covidotherD_2=1 if covidother_2==1|covidother_2==2|covidother_2==3
replace covidotherD_2=0 if covidother_2==0

 
** Encode missing values for multinational fault and China's fault variables
foreach var of varlist virus_china_1 multin_fault_1{
	replace `var' = . if `var' == 99
	assert 0 <= `var' <= 10 | `var' == .
}


** Normalize these variables to a 0-1 scale
foreach var of varlist probvaccino_1 probinfected_1 probsill_1 virus_china_1 multin_fault_1 noenoughknowledge_2 riskadv_1{
	replace `var' = `var' / 10
}

foreach var of varlist info_media_1 info_social_1 {
	replace `var' = `var' / 5
}


** Attrition variable
gen w1=1 if weights_1!=.
replace w1=0 if w1==.
gen w2=1 if weights_2!=.
replace w2=0 if w2==.
gen attrition=1 if w1==1 & w2==0
replace attrition=0 if w1==1 & w2==1


**Aggregated treatment variable
*Equal to 1 if the individual is assigned to one of the treatment groups
gen vac_treat = vac_infect_1 + vac_contag_1 + vac_country_1 + vac_econ_1
global treatments_short "vac_treat"


** Labels
label define country_label 49 "Germany" 61 "Australia" 43 "Austria" 33 "France" 39 "Italy" 64 "New Zealand" 44 "UK" 46 "Sweden" 1 "US" 101 "Poland" 
label values country_code country_label 
label variable young_1 "18-34 yo" 
label variable youngadult_1 "35-49 yo"
label variable fifty_1 "50-59 yo"
label variable old_1 "60+"	
label variable servicew_1 "Service workers"
label variable bluec_1 "Blue collar workers"
label variable inoperative_1 "Inactive"
label variable hs_1 "High school"
label variable college_1 "College"
label variable female_1 "Women"
label variable conservative_1 "Conservative"
label variable ideologydontknow_1 "Undeclared ideology"   
label variable probinfected_1 "Prob COVID"
label variable probsill_1 "Prob seriously ill"
label variable covidyou_1 "COVID"
label variable covidotherD_1 "Others w/COVID"
label variable livefamily_1 "Live w/family"
label variable info_media_1 "Traditional media consumption"
label variable info_social_1 "Social media consumption"
label variable overall_compliance_1 "Compliance"
label variable riskadv_1 "Risk aversion"
label variable multin_fault_1 "Big pharma's fault"
label variable virus_china_1 "China's fault"
label variable noenoughknowledge_2 "Vaccines' side effects"
label variable trustscientists_1 "Trust in scientists"
label variable probvaccino_1 "Vaccine Intentions"
label variable compliant_1 "Belief on the compliancy of others"
label variable gentrust_1 "Trust in general"
label variable feeling_low_1 "Feeling down"
label variable feeling_nointerest_1 "Low interest or pleasure in general"
label variable vac_infect_1 "Self-protection" 
label define vac_infect_1_label 1 "Self-protection" 0 "Not Self-protection"
label values vac_infect_1 vac_infect_1_label  
label variable vac_contag_1 "Protecting Others"
label define vac_contag_1_label 1 "Protecting Others" 0 "Not Protecting Others"
label values vac_contag_1 vac_contag_1_label 
label variable vac_country_1 "Protecting Health"
label define vac_country_1_label 1 "Protecting Health" 0 "Not Protecting Health"
label values vac_country_1 vac_country_1_label 
label variable vac_econ_1 "Protecting the Economy"
label define vac_econ_1_label 1 "Protecting the Economy" 0 "Not Protecting the Economy"
label values vac_econ_1 vac_econ_1_label 
label variable vac_treat "Treated"
label define vac_treat_label 1 "Treated" 0 "Not treated"
label values vac_treat vac_treat_label 
label variable attrition "Attrition" 
label variable solvaccino_1 "Vaccine is the solution (1st wave)"
label variable solvaccino_2 "Vaccine is the solution (2nd wave)"

** Macros for control variables and treatments variables

global controls "youngadult_1 fifty_1 old_1 female_1 hs_1 college_1 servicew_1 bluec_1 inoperative_1 info_media_1 info_social_1 overall_compliance_1 livefamily_1 covidyou_1 covidotherD_1 probinfected_1 probsill_1  conservative_1 ideologydontknow_1 trustscientists_1 riskadv_1 multin_fault_1 virus_china_1 noenoughknowledge_2"

global treatments "1.vac_infect_1 1.vac_contag_1 1.vac_country_1 1.vac_econ_1"

local var_to_keep_controls "probvaccino_1 youngadult_1 fifty_1 old_1 female_1 hs_1 college_1 servicew_1 bluec_1 inoperative_1 conservative_1 ideologydontknow_1 probinfected_1 probsill_1 covidyou_1 covidotherD_1 livefamily_1 info_media_1 info_social_1 overall_compliance_1 riskadv_1 multin_fault_1 virus_china_1 noenoughknowledge_2 trustscientists_1"




***** II. Graphs ******

********** REGRESSIONS FOR GRAPHS *******

reg probvaccino_1 $treatments i.country_code if vaccinedone!=., r
estimates store ExpIntall
reg vaccinedone $treatments i.country_code if probvaccino_1!=., r
estimates store ExpVaxall
reg vaccinedone $treatments i.country_code if probvaccino_1!=. & highmort_country==1, r
estimates store ExpVaxHM
reg vaccinedone $treatments i.country_code if probvaccino_1!=. & highmort_country==0, r
estimates store ExpVaxLM


**** Figure 1 ***
coefplot   (ExpIntall, pstyle(p3))  , bylabel(Vaccination Intentions, All) ///
		 || (ExpVaxall, pstyle(p3)) ///
		 , keep( $treatments ) bylabel(Vaccination, All) xline(0)  
graph export figure1_march23.png, replace

**** Figure 2 -- march 2023 ***
coefplot   (ExpVaxHM, pstyle(p3))  , bylabel(Vaccination, High Mortality) ///
		 || (ExpVaxLM, pstyle(p3)) ///
		 , keep( $treatments ) bylabel(Vaccination, Low Mortality) xline(0)  
graph export figure2_march23.png, replace
		 
		
******** FIGURE SM ******
*** Regressions ***
reg probvaccino_1 $treatments i.country_code if vaccinedone!=. & highmort_country==1, cluster(region_id)
estimates store Hint
reg vaccinedone $treatments i.country_code if probvaccino_1!=. & highmort_country==1, cluster(region_id)
estimates store Hvax


*** Figure S.1 - Coefs plot ***
coefplot   (Hint, pstyle(p3))  , bylabel(Vax Intentions, High Mortality) ///
		 || (Hvax, pstyle(p3))  ///
		 , keep( $treatments ) bylabel(Vaccination, High Mortality) xline(0)  

		 

********** III. TABLES **********

******** Table S2 *******
global demo_controls "fiftyplus_1 female_1 nohs_1 covidno_1 liveothers_1 livefamily_1 info_radio_1 info_newpaper_1 info_social_1 info_internet_1 liberal_1 centrist_1 conservative_1"

reg w2 $demo_controls i.country_code if probvaccino_1!=., r 
outreg2 using s2.xls, replace br bdec(3) ctitle(Demographics) 
reg w2 $demo_controls probvaccino_1 i.country_code if probvaccino_1!=., r 
outreg2 using s2.xls, append br bdec(3) ctitle(Demo & Intentions) 


******** Table S4 *******
matrix summary = J(35,5,.)
matrix colnames summary = "Obs" "Mean" "Std. dev." "Min" "Max"
matrix rownames summary = "18-34 yo" "35-49 yo" "50-59 yo" "65+" "Women" "White collars" "Service workers" "Blue collars" "Inactive" "No High School" "High school" "College" "Media Info" "Social Info" "Compliance" "Live w/family" "COVID" "Others w/COVID" "Prob COVID" "Prob Seriously Ill" "Live w/Family" "Conservative" "Centrist" "Liberal" "Undeclared Ideology" "Trust in Scientists" "Risk Aversion" "Big Pharma's Fault" "China's Fault" "Vaccines' Side Effects" "Vaccine Intentions" "Self Protection" "Protecting Others" "Protecting Own Country" "Protecting the Economy"

local i = 1
foreach var of varlist young_1 youngadult_1 fifty_1 old_1 female_1 whitec_1 servicew_1 bluec_1 inoperative_1 nohs_1 hs_1 college_1 info_media_1 info_social_1 overall_compliance_1 livefamily_1 covidyou_1 covidotherD_1 probinfected_1 probsill_1 livefamily_1 conservative_1 centrist_1 liberal_1 ideologydontknow_1 trustscientists_1 riskadv_1 multin_fault_1 virus_china_1 noenoughknowledge_2 probvaccino_1 vac_infect_1 vac_contag_1 vac_country_1 vac_econ_1 {
	
	*sum `var' if vaccinedone!=. & probvaccino_1!=. & multin_fault_1!=. & virus_china_1!=. , d
	sum `var' if `var'!=. & vaccinedone != . & probvaccino_1 != ., d
	matrix summary[`i',1] = r(N)
	matrix summary[`i',2] = round(r(mean), 0.01)
	matrix summary[`i',3] = round(r(sd), 0.01)
	matrix summary[`i',4] = round(r(min), 0.01)
	matrix summary[`i',5] = round(r(max), 0.01)
	local i = `i' + 1
}

putexcel set "`output_tables_path'\main\tableS4.xlsx", replace
putexcel A1 = matrix(summary), names


******** Table S5 *******
reg young_1 $treatments if probvaccino_1!=. & vaccinedone!=., cluster(region_id)  //TVC : Add country fixed effects for balance test ? 
outreg2 using "s5.xls", replace br label ctitle(`lab') bdec(3) title(Balance Test) drop(i.country_code) 

foreach y of global controls {
	local lab : var label `y'
	reg `y' $treatments if probvaccino_1!=. & vaccinedone!=., cluster(region_id)           //TVC : Add country fixed effects for balance test ? 
	outreg2 using "s5.xls", append br label ctitle(`lab') bdec(3) title(Balance Test) drop(i.country_code) 
}

local lab : var label attrition
reg attrition $treatments if probvaccino_1!=. , cluster(region_id)                     //TVC : Add country fixed effects for balance test ? 
outreg2 using "s5.xls", append br label bdec(3) ctitle(`lab') drop(i.country_code) 


******* Table S6 ******

reg probvaccino_1 $treatments i.country_code if probvaccino_1!=. & vaccinedone!=., r
test 1.vac_infect_1 1.vac_contag_1 1.vac_country_1 1.vac_econ_1
local joint = r(p)
test 1.vac_infect_1 = (1.vac_contag_1 + 1.vac_country_1 + 1.vac_econ_1) / 3
local difference = r(p)
outreg2 using s6.xls, replace br bdec(3) ctitle(Intentions, all) keep( $treatments ) 
 
reg vaccinedone $treatments i.country_code if probvaccino_1!=., r
test 1.vac_infect_1 1.vac_contag_1 1.vac_country_1 1.vac_econ_1
local joint = r(p)
test 1.vac_infect_1 = (1.vac_contag_1 + 1.vac_country_1 + 1.vac_econ_1) / 3
local difference = r(p)
outreg2 using s6.xls, append br bdec(3) ctitle(Vaccination, all) keep( $treatments )

reg vaccinedone $treatments i.country_code if probvaccino_1!=. & highmort_country==1, r
test 1.vac_infect_1 1.vac_contag_1 1.vac_country_1 1.vac_econ_1
local joint = r(p)
test 1.vac_infect_1 = (1.vac_contag_1 + 1.vac_country_1 + 1.vac_econ_1) / 3
local difference = r(p)
outreg2 using s6.xls, append br bdec(3) ctitle(Vaccination, High Mortality) keep( $treatments )

reg vaccinedone $treatments i.country_code if probvaccino_1!=. & highmort_country==0, r
test 1.vac_infect_1 1.vac_contag_1 1.vac_country_1 1.vac_econ_1
local joint = r(p)
test 1.vac_infect_1 = (1.vac_contag_1 + 1.vac_country_1 + 1.vac_econ_1) / 3
local difference = r(p)
outreg2 using s6.xls, append br bdec(3) ctitle(Vaccination, Low Mortality) keep( $treatments )


******** Table S7 ******

reg probvaccino_1 $treatments i.country_code if vaccinedone!=., r
test 1.vac_infect_1 1.vac_contag_1 1.vac_country_1 1.vac_econ_1
local joint = r(p)
test 1.vac_infect_1 = (1.vac_contag_1 + 1.vac_country_1 + 1.vac_econ_1) / 3
local difference = r(p)
outreg2 using s7.xls, replace br bdec(3) ctitle(Intentions, Panel) 

reg probvaccino_1 $treatments i.country_code , r
test 1.vac_infect_1 1.vac_contag_1 1.vac_country_1 1.vac_econ_1
local joint = r(p)
test 1.vac_infect_1 = (1.vac_contag_1 + 1.vac_country_1 + 1.vac_econ_1) / 3
local difference = r(p)
outreg2 using s7.xls, append br bdec(3) ctitle(Intentions, 1st Wave) 

******** Table S8 ******
reg probvaccino_1 $treatments $demo_controls i.country_code if vaccinedone!=., r
test 1.vac_infect_1 1.vac_contag_1 1.vac_country_1 1.vac_econ_1
local joint = r(p)
test 1.vac_infect_1 = (1.vac_contag_1 + 1.vac_country_1 + 1.vac_econ_1) / 3
local difference = r(p)
outreg2 using s8.xls, replace br bdec(3) ctitle(Intentions) 

reg vaccinedone $treatments $demo_controls i.country_code if probvaccino_1!=., r
test 1.vac_infect_1 1.vac_contag_1 1.vac_country_1 1.vac_econ_1
local joint = r(p)
test 1.vac_infect_1 = (1.vac_contag_1 + 1.vac_country_1 + 1.vac_econ_1) / 3
local difference = r(p)
outreg2 using s8.xls, append br bdec(3) ctitle(Vaccination) 

reg vaccinedone $treatments $demo_controls i.country_code if probvaccino_1!=. & highmort_country==1, r
test 1.vac_infect_1 1.vac_contag_1 1.vac_country_1 1.vac_econ_1
local joint = r(p)
test 1.vac_infect_1 = (1.vac_contag_1 + 1.vac_country_1 + 1.vac_econ_1) / 3
local difference = r(p)
outreg2 using s8.xls, append br bdec(3) ctitle(Vaccination, High Mortality) 

reg vaccinedone $treatments $demo_controls i.country_code if probvaccino_1!=. & highmort_country==0, r
test 1.vac_infect_1 1.vac_contag_1 1.vac_country_1 1.vac_econ_1
local joint = r(p)
test 1.vac_infect_1 = (1.vac_contag_1 + 1.vac_country_1 + 1.vac_econ_1) / 3
local difference = r(p)
outreg2 using s8.xls, append br bdec(3) ctitle(Vaccination, Low Mortality)


******** Table S9 ******

gen f_vac_treat=female_1*vac_treat 
gen coll_vac_treat=college_1*vac_treat 
gen aged50p=fifty_1+old_1
gen aged50p_vac_treat=aged50p*vac_treat 

reg probvaccino_1 vac_treat female_1 f_vac_treat i.country_code if probvaccino_1!=., r
test 1.vac_infect_1 1.vac_contag_1 1.vac_country_1 1.vac_econ_1
local joint = r(p)
test 1.vac_infect_1 = (1.vac_contag_1 + 1.vac_country_1 + 1.vac_econ_1) / 3
local difference = r(p)
outreg2 using s9.xls, replace br bdec(3) ctitle(Intentions, Women) 

reg vaccinedone vac_treat female_1 f_vac_treat i.country_code if probvaccino_1!=., r
test 1.vac_infect_1 1.vac_contag_1 1.vac_country_1 1.vac_econ_1
local joint = r(p)
test 1.vac_infect_1 = (1.vac_contag_1 + 1.vac_country_1 + 1.vac_econ_1) / 3
local difference = r(p)
outreg2 using s9.xls, replace br bdec(3) ctitle(Vaccination, Women) 

reg probvaccino_1 vac_treat college_1 coll_vac_treat i.country_code if probvaccino_1!=., r
test 1.vac_infect_1 1.vac_contag_1 1.vac_country_1 1.vac_econ_1
local joint = r(p)
test 1.vac_infect_1 = (1.vac_contag_1 + 1.vac_country_1 + 1.vac_econ_1) / 3
local difference = r(p)
outreg2 using s9.xls, append br bdec(3) ctitle(Intentions, college) 

reg vaccinedone vac_treat college_1 coll_vac_treat i.country_code if probvaccino_1!=., r
test 1.vac_infect_1 1.vac_contag_1 1.vac_country_1 1.vac_econ_1
local joint = r(p)
test 1.vac_infect_1 = (1.vac_contag_1 + 1.vac_country_1 + 1.vac_econ_1) / 3
local difference = r(p)
outreg2 using s9.xls, append br bdec(3) ctitle(Vaccination, college) 

reg probvaccino_1 vac_treat aged50p aged50p_vac_treat i.country_code if probvaccino_1!=., r
test 1.vac_infect_1 1.vac_contag_1 1.vac_country_1 1.vac_econ_1
local joint = r(p)
test 1.vac_infect_1 = (1.vac_contag_1 + 1.vac_country_1 + 1.vac_econ_1) / 3
local difference = r(p)
outreg2 using s9.xls, append br bdec(3) ctitle(Intentions, aged50p) 

reg vaccinedone vac_treat aged50p aged50p_vac_treat i.country_code if probvaccino_1!=., r
test 1.vac_infect_1 1.vac_contag_1 1.vac_country_1 1.vac_econ_1
local joint = r(p)
test 1.vac_infect_1 = (1.vac_contag_1 + 1.vac_country_1 + 1.vac_econ_1) / 3
local difference = r(p)
outreg2 using s9.xls, append br bdec(3) ctitle(Vaccination, aged50p) 



